﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using System.Linq;
using System.Collections.Generic;
using Model;
namespace DAL
{
    /// <summary>
    /// 数据访问类:PMS_RoleList
    /// </summary>
    public class PMS_RoleListDAL
    {
        public PMS_RoleListDAL()
        { }

        /// <summary>
        /// 查询用户所有数据
        /// </summary>
        /// <returns></returns>
        public List<PMS_RoleList> GetList(string strWhere)
        {
            string sql = @"select * from PMS_RoleList where isDelete='0' ";
            if (!string.IsNullOrEmpty(strWhere))
            {
                sql += " and " + strWhere;
            }
            return SqlHelper.GetDataByColumnsLst<PMS_RoleList>(Comm.Config.PMS, sql);
        }

        /// <summary>
        /// 单条数据
        /// </summary>
        /// <param name="roleID"></param>
        /// <returns></returns>
        public PMS_RoleList GetModel(int roleID)
        {
            string sql = @"select * from PMS_RoleList
where isDelete='0' and roleID='" + roleID + "'";
            return SqlHelper.GetDataByColumns<PMS_RoleList>(Comm.Config.PMS, sql);
        }

        #region  Method
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Model.PMS_RoleList model)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@roleText", SqlDbType.NVarChar,50),
					new SqlParameter("@roleDescription", SqlDbType.NVarChar,50),
					new SqlParameter("@parentID", SqlDbType.Int,4)};
            parameters[0].Value = model.roleText;
            parameters[1].Value = model.roleDescription;
            parameters[2].Value = model.parentID;

            int rows = SqlHelper.ExecuteNonQuery(Comm.Config.PMS, CommandType.StoredProcedure, "sp_AddRoleList", parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.PMS_RoleList model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update PMS_RoleList set ");
            strSql.Append("roleText=@roleText,");
            strSql.Append("roleDescription=@roleDescription");
            strSql.Append(" where roleID=@roleID");
            SqlParameter[] parameters = {
					new SqlParameter("@roleID", SqlDbType.Int,4),
					new SqlParameter("@roleText", SqlDbType.NVarChar,50),
					new SqlParameter("@roleDescription", SqlDbType.NVarChar,50)};
            parameters[0].Value = model.roleID;
            parameters[1].Value = model.roleText;
            parameters[2].Value = model.roleDescription;

            int rows = SqlHelper.ExecuteNonQuery(Comm.Config.PMS, CommandType.Text, strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int roleID)
        {
            //该表无主键信息，请自定义主键/条件字段
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update PMS_RoleList set isDelete='1' ");
            strSql.Append(" where roleID=@roleID");
            SqlParameter[] parameters = {
                                            new SqlParameter("@roleID",roleID)
};

            int rows = SqlHelper.ExecuteNonQuery(Comm.Config.PMS, CommandType.Text, strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        #endregion  Method
    }
}

